package com.youchuang.action.user;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.ReceiveAddress;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.UserService;

/**
 * 用户地址的插入
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class AddAddressAction extends BaseAction {

	private Logger logger = Logger.getLogger(AddAddressAction.class.getSimpleName());

	private int id;
	private int userId;
	private String receiveName;
	private String fullAddress;
	private String postalCode;
	private String mobile;
	private String phone;
	
	@Resource
	private UserService userService;

	@Action(value = "addAddress", results = { @Result(name = ActionSupport.SUCCESS, type = "redirectAction", params = {
			"namespace", "/user", "actionName", "selectAddress" }) })
	public String execute() throws Exception {
		logger.info("AddAddressAction is execute");
		String userId = ((User) session.get(Constant.S_USER)).getId();
		ReceiveAddress receiveAddress = new ReceiveAddress();
		receiveAddress.setFullAddress(fullAddress);
		receiveAddress.setMobile(mobile);
		receiveAddress.setPhone(phone);
		receiveAddress.setPostalCode(postalCode);
		receiveAddress.setReceiveName(receiveName);
		receiveAddress.setUserId(userId);

		userService.saveReceiveAddress(receiveAddress);

		return Constant.SUCCESS;
	}

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getReceiveName() {
		return receiveName;
	}

	public void setReceiveName(String receiveName) {
		this.receiveName = receiveName;
	}

	public String getFullAddress() {
		return fullAddress;
	}

	public void setFullAddress(String fullAddress) {
		this.fullAddress = fullAddress;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

}
